package com.ruoyi.web.controller.system.city;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.city.CityTrade;
import com.ruoyi.system.domain.city.CityTradeSecond;
import com.ruoyi.system.service.city.ICityTradeSecondService;
import com.ruoyi.system.service.city.ICityTradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RequestMapping({"/system/city/secondTrade"})
@RestController
/* loaded from: CityTradeSecondController.class */ public class CityTradeSecondController extends BaseController {
    @Autowired
    private ICityTradeSecondService cityTradeSecondService;
    @Autowired
    private ICityTradeService       cityTradeService;

    @GetMapping({"/list"})
    @PreAuthorize("@ss.hasPermi('city:secondTrade:list')")
    public TableDataInfo list(CityTradeSecond cityTradeSecond) {
        startPage();
        return getDataTable(this.cityTradeSecondService.selectCityTradeSecondList(cityTradeSecond));
    }

    @Log(title = "二级行业", businessType = BusinessType.EXPORT)
    @PostMapping({"/export"})
    @PreAuthorize("@ss.hasPermi('city:secondTrade:export')")
    public void export(HttpServletResponse response, CityTradeSecond cityTradeSecond) {
        new ExcelUtil<>(CityTradeSecond.class).exportExcel(response, this.cityTradeSecondService.selectCityTradeSecondList(cityTradeSecond), "二级行业数据");
    }

    @GetMapping({"/{tradeSecondId}"})
    @PreAuthorize("@ss.hasPermi('city:secondTrade:query')")
    public AjaxResult getInfo(@PathVariable("tradeSecondId") Long tradeSecondId) {
        return success(this.cityTradeSecondService.selectCityTradeSecondByTradeSecondId(tradeSecondId));
    }

    @Log(title = "二级行业", businessType = BusinessType.INSERT)
    @PostMapping
    @PreAuthorize("@ss.hasPermi('city:secondTrade:add')")
    public AjaxResult add(@RequestBody CityTradeSecond cityTradeSecond) {
        cityTradeSecond.setTradeSecondId(Long.valueOf(IdUtil.getSnowflake(1, 1).nextId()));
        CityTrade cityTrade = this.cityTradeService.selectCityTradeByTradeId(cityTradeSecond.getTradeId());
        if (cityTrade != null) {
            cityTradeSecond.setTradeName(cityTrade.getTradeName());
        }
        return toAjax(this.cityTradeSecondService.insertCityTradeSecond(cityTradeSecond));
    }

    @Log(title = "二级行业", businessType = BusinessType.UPDATE)
    @PutMapping
    @PreAuthorize("@ss.hasPermi('city:secondTrade:edit')")
    public AjaxResult edit(@RequestBody CityTradeSecond cityTradeSecond) {
        CityTrade cityTrade = this.cityTradeService.selectCityTradeByTradeId(cityTradeSecond.getTradeId());
        if (cityTrade != null) {
            cityTradeSecond.setTradeName(cityTrade.getTradeName());
        }
        return toAjax(this.cityTradeSecondService.updateCityTradeSecond(cityTradeSecond));
    }

    @Log(title = "二级行业", businessType = BusinessType.DELETE)
    @DeleteMapping({"/{tradeSecondIds}"})
    @PreAuthorize("@ss.hasPermi('city:secondTrade:remove')")
    public AjaxResult remove(@PathVariable Long[] tradeSecondIds) {
        return toAjax(this.cityTradeSecondService.deleteCityTradeSecondByTradeSecondIds(tradeSecondIds));
    }
}
